#ifndef __IO_CONTEXT_POOL__
#define __IO_CONTEXT_POOL__

#include <boost/asio.hpp>
#include <vector>
#include <memory>
#include <thread>


class AsioContextPool
{
public:
    using IOContext = boost::asio::io_context;
    using Work = boost::asio::io_context::work;
    using WrokPtr = std::unique_ptr<Work>;

    AsioContextPool(std::size_t size = std::thread::hardware_concurrency());
    ~AsioContextPool();

    IOContext& get_io_context();
    void stop();

    std::size_t get_thread_size() const { return _thread_size; }
    
private:
    std::vector<IOContext> _io_contexts;
    std::vector<WrokPtr> _works;
    std::vector<std::thread> _threads;
    std::size_t _thread_size;
    std::size_t _next;
};


#endif // !__IO_CONTEXT_POOL__
